<?php
defined('LMO') or die('Can\'t access !');

class LLayout
{
	static $instance;
	private function __constructor(){}

	public static function getInstance()
	{
		if(!isset(self::$instance)) {
			self::$instance = new LLayout();
		}
		
		return self::$instance;
	}
    
    public static function assign($file, $data = null, $display = false)
    {
        $f = APP.BS.'template'.BS.$file.'.php';
        if(!file_exists($f)) die('File '.$file.'.php doesn\'t exist !');
        $html = null;
        if(is_array($data) && !empty($data)) {
            foreach($data as $key => $value) {
                $$key = $value;
            }
        }
        //unset($data);
        ob_start();
        include ($f);
        $html = ob_get_contents();
        ob_end_clean();
        
        if($display == true) {
            echo $html;
        } else {
            return $html;
        }
    }
    
    public static function loadLayout($html = null, $return = false)
    {
        $f = APP.BS.'template'.BS.'layout.php';
        
        if(!file_exists($f)) die('File layout.php doesn\'t exist !');
        
        $data = null;
        ob_start();
        include($f);
        $data = ob_get_contents();
        ob_end_clean();
        if($return == true) {
            return $data;
        } else {
            echo $data;
        }
    }
}

?>
